package com.boot.dongli.alternate;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageBuilder;
import org.springframework.amqp.rabbit.core.RabbitTemplate;

import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Date;

/**
 * @Author: lkz
 * @Title: AlternateProMsg
 * @Description: 备用交换机
 * 备份交换机 一定要选址fanout广播模式 因为原交换机转入备份交换机时并不会指定路由键
 * @Date: 2023/10/16 17:18
 */
@Component
@Slf4j
public class AlternateProMsg {


    @Resource
    private RabbitTemplate rabbitTemplate;


    public void sendMsg(){
        Message message= MessageBuilder.withBody("hello world".getBytes())
                .build();
        rabbitTemplate.convertAndSend("alternate.exchange","info",message);
        log.info("消息发送完毕，发送时间为：{}",new Date());
    }

}
